﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace MIS.Logistics.Website.Models
{
    /// <summary>
    /// 模拟数据库
    /// </summary>
    public class Database
    {
        public static List<User> Users;
        public static List<Role> Roles;
        public static List<UserRole> UserRoles;
        public static List<ControllerAction> ControllerActions;
        public static List<ControllerActionRole> ControllerActionRoles;

        static Database()
        {
            // 初始化用户
            Users = new List<User>()
            {
                new User(){Id=1,Name="Admin"},
                new User(){Id=2,Name ="User"},
                new User(){Id=3,Name="Guest"}
            };

            Roles = new List<Role>()
            {
                new Role() {Id=1,Name="Administrator"},
                new Role() {Id=2,Name="User"}
            };

            UserRoles = new List<UserRole>()
            {
                 new UserRole(){Id=1,RoleId=1,UserId=1}, //管理员
                 new UserRole(){Id=2,RoleId=2,UserId=2} //用户
            };

            ControllerActions = new List<ControllerAction>()
            {
                new ControllerAction(){Id=1,Name="Index",IsController=true,IsAllowedNoneRoles=true,IsAllowedAllRoles=true}, // /Home 允许所有人访问

                new ControllerAction(){Id=2,ControllName="Home",Name="Admin",IsController=false,IsAllowedNoneRoles=false,IsAllowedAllRoles = false}, // /Home/Admin 管理员才能访问

                new ControllerAction(){Id=3,ControllName="Home",Name="User",IsController=false,IsAllowedNoneRoles=false,IsAllowedAllRoles = true}, // /Home/User 有角色的人才能访问
                
                new ControllerAction(){Id=4,ControllName="Home",Name="UserOnly",IsController=false,IsAllowedNoneRoles=false,IsAllowedAllRoles = false}, // /Home/UserOnly 用户才能访问

            };

            ControllerActionRoles = new List<ControllerActionRole>() { 
                new ControllerActionRole(){ Id=1,ControllerActioId = 2,RoleId = 1,IsAllowed = true },  // 管理员才能访问
                new ControllerActionRole(){ Id=2,ControllerActioId = 4,RoleId = 2,IsAllowed = true }  // USER才能访问
            };

        }
    }
}